/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable prettier/prettier */
/*
 * @Author: EyeSklear 1814580085@qq.com
 * @Date: 2024-01-02 14:38:59
 * @LastEditors: EyeSklear 1814580085@qq.com
 * @LastEditTime: 2024-05-15 16:38:50
 * @FilePath: \Scene_Back\src\main.ts
 * @Description:
 *
 * Copyright (c) 2024 by EyeSklear , All Rights Reserved.
 */
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpExceptionFilter } from './common/filter';
import { ResponseInterceptor } from './common/response';
import { NestExpressApplication } from '@nestjs/platform-express';
import { ValidationPipe } from '@nestjs/common';
import * as dotenv from 'dotenv';
import { WINSTON_LOGGER_TOKEN } from './winston/winston.module';

if (process.env.NODE_ENV === 'development') {
  dotenv.config({ path: '.env.development' }); // 加载开发环境 env 文件
} else if (process.env.NODE_ENV === 'production') {
  dotenv.config({ path: '.env.production' }); // 加载生产环境 env 文件
}
// dotenv.config();
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  // app.enableCors();
  app.enableCors({
    origin: '*', // 替换为你的前端域名
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
  });
  app.useGlobalInterceptors(new ResponseInterceptor());
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalPipes(new ValidationPipe());
  app.useLogger(app.get(WINSTON_LOGGER_TOKEN));
  await app.listen(`${process.env.VITE_PORT}`);
}
bootstrap();
